﻿using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Org.BouncyCastle.Asn1;
using Org.BouncyCastle.X509;

namespace TheClerk.Forms.Templates.raw.Envelope
{
    #region public Assertions
    /// <summary>
    /// Set of Assertion
    /// </summary>
    /// <remarks>
    /// Assertions ::= SEQUENCE(1..MAX) OF Assertion
    /// </remarks>
    internal class Assertions
    {
        internal List<Assertion> data;

        internal void AddAssertion(Assertion input)
        {
            data.Add(input);
        }

        internal Assertions()
        {
            data = new List<Assertion>();
        }

        internal Stream Serialize()
        {
            MemoryStream s = new MemoryStream();
            var o = new DerSequenceGenerator(s);
            
            foreach (var i in data)
                o.AddObject(i.ToAsn1Encodable());
            o.Close();
            s.Position = 0;
            return s;
        }

        internal Asn1Encodable ToAsn1Encodable()
        {
            return Asn1Sequence.FromStream(Serialize());
        }
        
        internal byte[] ToByteArray()
        {
            var s = Serialize();
            byte[] output = new byte[s.Length];
            System.Diagnostics.Debug.Assert(output.Length == s.Length);
            s.Read(output, 0, output.Length);
            return output;
        }

        /// <summary>
        /// return the throwaway Chop.
        /// </summary>
        /// <returns></returns>
        internal Chop GetOuterChop()
        {
            throw new NotImplementedException();
        }
    }
    #endregion
}
